package com.syq.courierDelivery.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.syq.courierDelivery.common.utils.PathPlanningUtils;
import com.syq.courierDelivery.entity.po.Express;
import com.syq.courierDelivery.entity.po.ExpressDelivery;
import com.syq.courierDelivery.entity.vo.MqReceiveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private PathPlanningUtils planningUtils;

    @GetMapping("/plan")
    @ResponseBody
    public String plan() {
        List<ExpressDelivery> expressDeliverys = new ArrayList<>();
        String[] ss = new String[3];
        ss[0] = "13418380.04,3648034.29";
        ss[1] = "13418210.55,3648062.99";
        ss[2] = "13418295.91,3648069.99";
        for(int i = 0; i < 3; i++) {
            ExpressDelivery expressDelivery = new ExpressDelivery();
            expressDelivery.setId((long) i+2);
            Express express = new Express();
            express.setCoordinate(ss[i]);
            expressDelivery.setExpress(express);
            expressDeliverys.add(expressDelivery);
        }
        MqReceiveVo vo = new MqReceiveVo();
        vo.setDeliveryList(expressDeliverys);
        vo.setType((byte)1);
        vo.setCenterCoordinate("13418381.71,3648073.03");
        List<ExpressDelivery> expressDeliveryList = planningUtils.pathPlan(vo);
        return JSON.toJSONString(expressDeliveryList);
    }
}
